<template>
    <div class="song-list">
        <!-- 歌单详情 -->
        <van-nav-bar
            title="歌单详情"
            left-text="返回"
            left-arrow
            @click-left="onClickLeft"
        />
        <!-- 歌单的顶部 -->
        <div class="header">
            <img :src="song.logo" alt="">
            <!-- 歌单标题 -->
            <h3>{{song.dissname}}</h3>
            <!-- 作者信息 -->
            <div class="nick">
                <img :src="song.headurl" alt="">
                <span>{{song.nickname}}</span>
            </div>
            <!-- <span>播放量:{{song.visitnum| numFilter(1)}}万</span> -->
        </div>
        <!-- 歌曲列表 -->
        <div class="list">
            <div v-for="(item,index) in songlist" :key="index" :title="item" class="song">
                    <h3>{{item.resource}}</h3>
                    <div class="songers">
                        <span v-for="(singer,index) in item.singer" :key="singer.id">
                            {{singer.name}}
                            <span v-show="index!=item.singer.length-1">/</span>
                        </span>
                        <span v-show="item.albumname">
                            <span>·</span>
                            <span>{{item.albumname}}</span>
                        </span>
                    </div>
                </div>
        </div>
    </div>
</template>

<script>
export default {
    data(){
        return{
        song: {
           logo: "", //歌单logo
           dissname: "", //歌单名称
           headurl: "", //歌单头像
           nickname: "", //歌单制作者名称
        //    visitnum: 0, //播放量
        },
           songlist: [], //歌曲列表
           songnum: 0, //歌曲数量
           list:[],//vant的list列表数据
           loading: false,//是否正在加载
           finished: false,//是否全部加载完成
        }
    },
    created(){
        this.getListData()
    },
    methods:{
        getListData(){
            this.$request('get','/album/detail',{
                id:this.$route.params.id
            })
            .then((res)=>{
                console.log(res)
                this.song.logo = res.album.coverUrl;
                this.song.dissname = res.album.albumname;
                this.song.headurl = res.album.artistAvatarUrl;
                this.song.nickname = res.album.artistName;
                // this.song.visitnum = res.playlist.playCount;
                this.songlist = res.product.descr;
                // this.songnum = res.playlist.trackCount;
                
            })
        },
        onClickLeft(){
            this.$router.go(-1);
        },
        onLoad(){
            setTimeout(() => {
                //注意splice和slice方法的差异
                this.list = this.list.concat(this.songlist.splice(0,10))
                // console.log(this.list)
                //加载状态结束
                this.loading = false;

                //数据全部加载完成
                if(this.list.length >= this.songnum){
                    this.finished = true;
                }
            }, 1000)
        }
    },
    filters:{
        //处理播放量的显示格式
        // param num：小数位固定的位数
        // param value:处理的数值
        numFilter(value,num){
            //把小数位固定为num位
            return parseFloat(value/10000).toFixed(num)
        }
    }
}
</script>

<style scoped>
.header > img{
    width: 50%;
    border-radius: 1rem;
}
.nick{
    overflow: hidden;
}
.nick>img{
    width: 1.5rem;
    border-radius: 50%;
    margin-right: 0.5rem;
}
.nick>span{
    height: 2rem;
    display: inline-block;
    vertical-align: middle;
    font-size: 0.8rem;
}
.header>span{
    font-size: 0.9rem;
}
.song{
    margin-bottom: 1rem;
}
.song>h3{
    text-align: left;
    font-size: 1rem;
    padding: 0 2rem;
    margin: 0;
}
.songers{
    text-align: left;
    padding: 0 2rem;
}
.songers span{
    font-size: 0.8rem;
    color: gray;
}
.songers>span:nth-last-child(1)>span:nth-child(1){
    margin: 0 0.3rem;
    font-weight: 900;
    color: red;
}
</style>


